package com.example.meitao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.meitao.R;
import com.example.meitao.bean.Say;
import com.squareup.picasso.Picasso;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by wudi on 2016/9/2.
 */
public class MySayAdapter extends RecyclerView.Adapter<MySayAdapter.MyRecycleViewHolder> {

    private List<Say.DataBean.ResultsBean> data;
    private Context mContext;
    private ImageOptions mOptions;

    public MySayAdapter(List<Say.DataBean.ResultsBean> data, Context mContext) {
        this.data = data;
        this.mContext = mContext;
        mOptions = new ImageOptions.Builder().setCircular(true).setUseMemCache(true).build();
    }

    @Override
    public MyRecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_say_test,null);
        MyRecycleViewHolder holder =new MyRecycleViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyRecycleViewHolder holder, int position) {

        Say.DataBean.ResultsBean resultsBean =data.get(position);
        holder.tv_say_name.setText(resultsBean.getUser().getNick());
        holder.tv_say_text.setText(resultsBean.getEname());
        holder.tv_say_money.setText(resultsBean.getPrice()+"");
        holder.tv_say_detail.setText(resultsBean.getEname());
        holder.tv_say_theam.setText(resultsBean.getHighlight());
        holder.tv_say_time.setText(resultsBean.getAgoInWords());
        if(!resultsBean.getEntitypicv2().isEmpty()){

            Picasso.with(mContext).load(resultsBean.getEntitypicv2().get(0).getFilename()).into(holder.iv_say_test);
        }else{
            Picasso.with(mContext).load(R.mipmap.sorry_nothing).into(holder.iv_say_test);
        }
        x.image().bind(holder.iv_say_title,resultsBean.getUser().getAvatar(),mOptions);

    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }


    public   static class MyRecycleViewHolder extends RecyclerView.ViewHolder{

        private ImageView iv_say_title,iv_say_test;
        private TextView tv_say_name,tv_say_text,tv_say_money,tv_say_detail;
        private TextView tv_say_theam,tv_say_time;
        public MyRecycleViewHolder(View itemView) {
            super(itemView);
            iv_say_title = (ImageView) itemView.findViewById(R.id.iv_say_title);
            iv_say_test = (ImageView) itemView.findViewById(R.id.iv_say_test);

            tv_say_name = (TextView) itemView.findViewById(R.id.tv_say_name);
            tv_say_text = (TextView) itemView.findViewById(R.id.tv_say_test);
            tv_say_money = (TextView) itemView.findViewById(R.id.tv_say_money);
            tv_say_detail = (TextView) itemView.findViewById(R.id.tv_say_detail);
            tv_say_theam = (TextView) itemView.findViewById(R.id.tv_say_theam);
            tv_say_time = (TextView) itemView.findViewById(R.id.tv_say_time);
        }
    }
}
